package leetcode;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @program: datastructureandalogorithm
 * @description:
 * @author: hmx
 * @create: 2022-02-09 11:36
 **/
public class LeetCode2164 {

    public int[] sortEvenOdd(int[] nums) {
        int n = nums.length;
        List<Integer> ji = new ArrayList<>();
        List<Integer> ou = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            if (i % 2 == 0) {
                ou.add(nums[i]);
            } else {
                ji.add(nums[i]);
            }
        }
        ji.sort((a, b) -> b - a);
        Collections.sort(ou);
        int i1 = 0;
        int i2 = 0;
        for (int i = 0; i < n; i++) {
            if (i % 2 == 0) {
                nums[i] = ou.get(i1++);
            } else {
                nums[i] = ji.get(i2++);
            }
        }
        return nums;
    }

}
